package com.kh.pajx.sop.service.sys.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.kh.pajx.sop.base.BaseServiceImpl;
import com.kh.pajx.sop.dao.sys.ISysDictionaryDao;
import com.kh.pajx.sop.domain.PageBean;
import com.kh.pajx.sop.domain.SysDictionary;
import com.kh.pajx.sop.service.sys.ISysDictionaryService;
import com.kh.pajx.sop.util.page.QueryHelper;
import com.kh.pajx.sop.util.page.QueryHelperForManyTable;

/**
 * 字典信息业务逻辑实现类
 * @author 马兴龙
 * @createDate 2014年6月20日 下午1:43:26
 */
@Service
@Transactional
public class SysDictionaryServiceImpl extends BaseServiceImpl<SysDictionary> implements ISysDictionaryService {

	@Resource
	private ISysDictionaryDao sysDictionaryDao;

	

	// ==>1.ISysDictionaryService重载方法
	
	@Override
	public List<SysDictionary> findDicListByType(String typeCode) throws Exception {
		return sysDictionaryDao.findDicListByType(typeCode);
	}
	
	// ==>2.IBaseService重载方法

	
	
	
	
	
	
	
	
	
	// =========================以下为需要整理或废弃方法===================================	

	@Override
	public void save(SysDictionary demo) {
		sysDictionaryDao.save(demo);
	}


	@Override
	public void update(SysDictionary demo) {
		sysDictionaryDao.update(demo);
	}


	@Override
	public SysDictionary getById(String uuid) {
		return sysDictionaryDao.getById(uuid);
	}


	@Override
	public PageBean getPageBean(int pageNum, int pageSize,
			QueryHelper queryHelper) {
		return sysDictionaryDao.getPageBean(pageNum, pageSize, queryHelper);
	}
	
	/**
	 * 通用分页查询 支持多表查询
	 * @param pageNum
	 * @param pageSize
	 * @param queryHelper
	 * @return   
	 * @author:	azzcsimp
	 * @Createdate:	2014年6月27日 上午11:46:46
	 */
	public PageBean getPageBean(int pageNum, int pageSize, QueryHelperForManyTable queryHelper){
		return sysDictionaryDao.getPageBean(pageNum, pageSize, queryHelper);
	}
	
	@Override
	public List<String> getDicTypeNameList() {
		return sysDictionaryDao.getDicTypeNameList();
	}
	
	@Override
	public List<SysDictionary> getDicTypeList() {
		return sysDictionaryDao.getDicTypeList();
	};
	
	
	@Override
	public List<?> getDicTypeListByTypeName(String dicTypeName) {
		return sysDictionaryDao.getDicTypeListByTypeName(dicTypeName);
	}
	
	
	/**
	 * 校验字典类型编码是否已存在
	 * @see com.kh.pajx.sop.service.sys.ISysDictionaryService#checkRepeatDicTypeCode(java.lang.String)
	 */
	@Override
	public boolean checkRepeatDicTypeCode(String dicTypeCode) {
		return sysDictionaryDao.checkRepeatDicTypeCode(dicTypeCode) > 0;
	}
	
	
	/**
	 * 校验同一字典类型编码下，类型名称是否存在
	 * @see com.kh.pajx.sop.service.sys.ISysDictionaryService#checkRepeatDicTypeName(java.lang.String, java.lang.String)
	 */
	@Override
	public boolean checkRepeatDicTypeName(String dicTypeCode, String dicTypeName) {
		return sysDictionaryDao.checkRepeatDicTypeName(dicTypeCode, dicTypeName) > 0 ;
	}
	
	/**
	 * 校验统一字典类型编码下，字典编码是否已存在
	 * @see com.kh.pajx.sop.service.sys.ISysDictionaryService#checkRepeatDicCode(java.lang.String, java.lang.String)
	 */
	@Override
	public boolean checkRepeatDicCode(String dicCode, String dicTypeCode) {
		return sysDictionaryDao.checkRepeatDicCode(dicCode, dicTypeCode) > 0;
	}
	
	/**
	 * 根据字典类型名称查找字典列表
	 * @see com.kh.pajx.sop.service.sys.ISysDictionaryService#getDicListByTypeName(java.lang.String)
	 */
	@Override
	public List<SysDictionary> getDicListByTypeName(String dicTypeName) {
		return sysDictionaryDao.getDicListByTypeName(dicTypeName);
	}
	
	/**
	 * 批量删除字典信息
	 * @see com.kh.pajx.sop.service.sys.ISysDictionaryService#delete(java.lang.String[])
	 */
	@Override
	public int delete(String[] uuids) {
		return sysDictionaryDao.delete(uuids);
	}


	@Override
	public List<SysDictionary> getDicListByTypeCode(String dicTypeCode) {
		return sysDictionaryDao.getDicListByTypeCode(dicTypeCode);
	}


	@Override
	public Map<String, List<SysDictionary>> getEveryDicType() {
		List<SysDictionary> list = sysDictionaryDao.findAll();
		Map<String,List<SysDictionary>> map = new HashMap<String,List<SysDictionary>>();
		if(list!=null){
		for (SysDictionary dic : list) {
			if(map.containsKey(dic.getDicTypeCode())){
				List<SysDictionary> dicList = map.get(dic.getDicTypeCode());
				dicList.add(dic);
			}else{
				List<SysDictionary> dicList = new ArrayList<SysDictionary>();
				dicList.add(dic);
				map.put(dic.getDicTypeCode(),dicList);
			}
		}
		}
		return map;
	}
	
	
	
}
